home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4705 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: llnews.ll.mit.edu!usenet
  2. From: kappu@ll.mit.edu (Kalpana Subramanian)
  3. Newsgroups: comp.lang.c++,gnu.g++.help,gnu.g++
  4. Subject: g++ warning about initialization of non-const obj& - help needed
  5. Date: 31 Jan 1996 16:41:34 GMT
  6. Organization: MIT Lincoln Laboratory
  7. Distribution: world
  8. Message-ID: <4eo63u$kr1@llnews.ll.mit.edu>
  9. Originator: rachel@sun46a
  10.  
  11. Hello g++ users,
  12.  
  13. I have a function declared as such:
  14.  
  15.     func( obj &)
  16.  
  17. I go to use it thus:
  18.  
  19.     func( obj.memberfunc() returning an obj);
  20.  
  21. I get a warning -
  22.  
  23.     warning: initialization of non-const `obj &' from rvalue `obj'
  24.  
  25. If I make a temporary obj, obj2 = obj.memberfunc()returning an obj,
  26. and call func(obj2), it compiles.
  27.  
  28. In reading the FAQ, I understand that temporaries inside function calls
  29. that require conversion can get deleted before the conversion process,
  30. thus causing erroneous results and should be avoided. However, in this
  31. usage, the compiler should be able to make a reference from an object,
  32. shouldn't it?  Is it that the compiler will only want to make a const
  33. reference from an object? The code I am compiling was all compiled under 
  34. previous versions of g++, and I wanted to upgrade it all. I am using 
  35. gcc/g++2.7.2 on a SunOS 4.1.4 platform.
  36.  
  37. If this is obvious to anybody, could you please explain what the
  38. issue is?
  39.  
  40. Thank you.
  41.  
  42. Kalpana Subramanian
  43.